#ifndef GRASS_H
#define GRASS_H
#include "../glutil/PortableGL.h"
#include "../util/NTuple.h"
#include "../geom/TerrainModel.h"
#include "../geom/Point3D.h"
#include "../glutil/shaderUtils.h"

#include <memory>
#include <vector>

namespace sceneelems{
	class Grass
	{
		private:
			class GrassTypeInfo
			{
				public:
					GrassTypeInfo() :textureID(0),vbufferID(0), tcbufferID(0), textureWidth(1), textureHeight(1), density(0), numElems(0){}

					GLuint textureID;
					GLuint vbufferID;
					GLuint tcbufferID;
					int textureWidth;
					int textureHeight;
					float density;
					int numElems;
					float scale;
					std::vector<geom::Point2D> grassTufts;
			};

			std::vector<GrassTypeInfo> m_grassTypes;
			std::vector<geom::Point3D> m_points;

			glutil::ShaderProgram * m_grassShader; 
			void generateVBO(GrassTypeInfo& grass, const std::vector<geom::Point3D> &points );
		public:
			/** Constructor*/
			Grass();
			/** Sets the ground texture
			  @param texture OpenGL texture ID of the texture to use*/
			void setTexture(unsigned int texture, int ID);
			/** Draws the ground */
			void draw(int windowWidth);
			void addGrassType(GLuint textureID, int textureWidth, int textureHeight, float density, float scale, const geom::TerrainModel &terrain);
			void updateTerrain(const geom::TerrainModel &terrain);
	};
}
#endif

